package com.hbut.bili.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hbut.bili.entity.Video;
import com.hbut.bili.service.IVideoService;

@Controller
@RequestMapping("/video")
public class VideoController {
	
	@Autowired
	private IVideoService videoService;
	
	@GetMapping("/add")
	public String videoAdd() {
		return "videoAdd";
	}
	
	@PostMapping("/addPost")
	public String videoAddPost(Video video) throws Exception {
		videoService.inserVideo(video);
		return "videoAddResult";
	}
	
	@GetMapping("/list")
	public String videoList(Model model) throws Exception {
		List<Video> videoList = videoService.selectVideoList();
		model.addAttribute("videoList", videoList);
		return "videoList";
	}
	
	@GetMapping("/show")
	public String videoShow(Long aid, Model model) throws Exception {
		Video video = videoService.selectVideoById(aid);
		model.addAttribute("video", video);
		return "videoShow";
	}

}
